# -*- coding: utf-8 -*-

"""
 (c) 2023 - Copyright CTyunOS Inc

 Authors:
   youyifeng <youyf2@chinatelecom.cn>

"""

from __future__ import unicode_literals, absolute_import

import os
import configparser

OSV_MAP = {
    'ctyunos2': '.ctl2',  # 'openEuler-20.03-LTS'
    'ctyunos3': '.ctl3',  # 'openEuler-22.03-LTS'
}

OPENEULER_PRODUCT_REPO_MAP = {
    'openEuler-20.03-LTS': [
        "https://mirrors.tuna.tsinghua.edu.cn/openeuler/openEuler-20.03-LTS/everything/x86_64/",
        "https://mirrors.tuna.tsinghua.edu.cn/openeuler/openEuler-20.03-LTS/update/x86_64/",
    ],
    'openEuler-20.03-LTS-SP1': [
        "https://mirrors.tuna.tsinghua.edu.cn/openeuler/openEuler-20.03-LTS-SP1/everything/x86_64/",
        "https://mirrors.tuna.tsinghua.edu.cn/openeuler/openEuler-20.03-LTS-SP1/update/x86_64/",
    ],
    'openEuler-20.03-LTS-SP2': [
        "https://mirrors.tuna.tsinghua.edu.cn/openeuler/openEuler-20.03-LTS-SP2/everything/x86_64/",
        "https://mirrors.tuna.tsinghua.edu.cn/openeuler/openEuler-20.03-LTS-SP2/update/x86_64/",
    ],
    'openEuler-20.03-LTS-SP3': [
        "https://mirrors.tuna.tsinghua.edu.cn/openeuler/openEuler-20.03-LTS-SP3/everything/x86_64/",
        "https://mirrors.tuna.tsinghua.edu.cn/openeuler/openEuler-20.03-LTS-SP3/update/x86_64/",
    ],
    # 'openEuler-20.09': [], deprecated
    # 'openEuler-21.03': [], deprecated
    # 'openEuler-21.09': [], deprecated
    'openEuler-22.03-LTS': [
        "https://mirrors.tuna.tsinghua.edu.cn/openeuler/openEuler-22.03-LTS/everything/x86_64/",
        "https://mirrors.tuna.tsinghua.edu.cn/openeuler/openEuler-22.03-LTS/update/x86_64/",
    ],
    'openEuler-22.03-LTS-SP1': [
        "https://mirrors.tuna.tsinghua.edu.cn/openeuler/openEuler-22.03-LTS-SP1/everything/x86_64/",
        "https://mirrors.tuna.tsinghua.edu.cn/openeuler/openEuler-22.03-LTS-SP1/update/x86_64/",
    ],
    'openEuler-22.09': [
        "https://mirrors.tuna.tsinghua.edu.cn/openeuler/openEuler-22.09/everything/x86_64/",
        "https://mirrors.tuna.tsinghua.edu.cn/openeuler/openEuler-22.09/update/x86_64/",
    ],
    'ctyunos2': [
        "http://192.168.33.76/ctyun/ctyunos/ctyunos-2/2.0.1/everything/x86_64/",
        "http://192.168.33.76/ctyun/ctyunos/ctyunos-2/2.0.1/update/x86_64/",
    ]
}


def load_config(configfile):
    default_values = {
        'main': {
            "log_level": "debug",
            "workdir": "/usr/share/cve-ease/",
            "db_type": "sqlite",
            "db_file": "cve-ease.db",
            "db_user": "",
            "db_password": "",
            "db_host": "",
            "db_port": "",
            "log_file": "cve-ease.log",
            "pid_file": "cve-ease.pid",
            "lock_file": "cve-ease.lock",
        }
    }
    config = configparser.ConfigParser()
    # read default config from default ditct
    config.read_dict(default_values)
    if not os.path.exists(configfile):
        print("%s config file not found!" % configfile)
        exit(1)
    # reload config from configfile
    config.read(configfile)

    return config
